import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:yt_devops/components/app_bar/app_bar_widget.dart';
import 'package:yt_devops/components/brn/brn_input_text.dart';
import 'package:yt_devops/components/brn/brn_select_tag.dart';
import 'package:yt_devops/components/select_phone_widget.dart';
import 'package:yt_devops/components/yt_button.dart';
import 'package:yt_devops/resources/str_res_keys.dart';
import 'package:yt_devops/styles/styles.dart';
import 'package:yt_devops/utils/enums.dart';
import 'finish_task_controller.dart';

class FinishTaskPage extends GetView<FinishTaskController> {
  const FinishTaskPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: Colour.white,
        appBar: AppBarWidget.defaultAppBar(ResKey.taskProcessInfo.tr),
        body: GetBuilder<FinishTaskController>(
          builder: (controller) => Padding(
            padding: EdgeInsets.fromLTRB(16.w, 20.h, 16.w, 51.w),
            child:
                Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
              controller.events.isEmpty
                  ? SizedBox(
                      height: 50.h,
                    )
                  : YtBrnSelectTag(
                      tags: controller.eventNames,
                      spacing: 12,
                      tagWidth: 165.w,
                      tagHeight: 34.h,
                      tagTextStyle: TextStyles.f14,
                      singleSelectIndex: 0,
                      selectBorder: Border.all(color: Colour.primaryColor),
                      selectedTagTextStyle: TextStyles.pf14.boldStyle,
                      onSelect: (selectedIndexes) {
                        controller.selectedTagIndex = selectedIndexes[0];
                      }),
              SizedBox(
                height: 14.h,
              ),
              if (controller.type == TaskType.install)
                getUploadWidget()
              else
                ...descriptWidget(),
              Expanded(
                  child: Align(
                alignment: Alignment.bottomCenter,
                child: YtButton(
                  text: ResKey.confirm.tr,
                  radius: BorderRadius.circular(10.w),
                  size: Size(311.w, 48.8.h),
                  onPress: controller.commit,
                ),
              ))
            ]),
          ),
        ));
  }

  Widget getUploadWidget() {
    return SelectPhotoWidget(
      controller.uploadImageList,
      true,
      3,
      photoWidth: 84,
      titleFontSize: 16,
      titleString: ResKey.uploadPic.tr,
      (List<String> list) {
        controller.uploadImageList = list;
        controller.update();
      },
    );
  }

  List<Widget> descriptWidget() {
    return [
      Text(
        '${ResKey.uploadVoucher.tr} （${ResKey.atMost3Peaces.tr}）',
        style: TextStyle(
            color: Colour.mainTextColor,
            fontSize: 16.sp,
            fontWeight: FontWeight.bold,
            height: 2),
      ),
      YBrnInputText(
          minHeight: 120.h,
          maxLength: 200,
          minLines: 5,
          padding: EdgeInsets.all(16.w),
          onTextChange: controller.onChangehandle,
          onSubmit: (input) {
            controller.description = input;
            controller.commit();
          },
          bgColor: Colour.backgroundColor)
    ];
  }
}
